package com.yuke.cloud.service.wmc.service.impl;

import com.yuke.cloud.common.core.support.BaseService;
import com.yuke.cloud.service.api.smc.dto.ShopInfoDto;
import com.yuke.cloud.service.api.smc.service.SmcFeignApi;
import com.yuke.cloud.service.api.uac.service.UacUserFeignApi;
import com.yuke.cloud.service.wmc.dao.WmsWarehouseShopMapper;
import com.yuke.cloud.service.wmc.entity.WmsWarehouseShop;
import com.yuke.cloud.service.wmc.service.WmsWarehouseGroupService;
import com.yuke.cloud.service.wmc.service.WmsWarehouseShopService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Created by zys on 2018/11/13.
 */
@Service
@Transactional
public class WmsWarehouseShopServiceImpl extends BaseService<WmsWarehouseShop> implements WmsWarehouseShopService {
    @Resource
    private WmsWarehouseShopMapper wmsWarehouseShopMapper;
    @Resource
    private WmsWarehouseGroupService wmsWarehouseGroupService;
    @Resource
    private SmcFeignApi smcFeignApi;
    @Resource
    private UacUserFeignApi uacUserFeignApi;


    @Override
    public List<WmsWarehouseShop> getbyshopid(List<Long> list) {
        return wmsWarehouseShopMapper.getbyshopid(list);
    }

    @Override
    public void beathdelete(List<Long> ids) {
        wmsWarehouseShopMapper.beathdelete(ids);
    }

    @Override
    public int doit(List<Long> list) {
        return wmsWarehouseShopMapper.doit(list);
    }

    @Override
    public List<Map> getWarehouseNamebyShopId(List<Long> shopids) {
        return wmsWarehouseShopMapper.getWarehouseNamebyShopId(shopids);
    }

    @Override
    public List<Map> getbyforeachsql(List<Long> shopids) {
        return wmsWarehouseShopMapper.getWarehouseNamebyShopId(shopids);
    }

    @Override
    public List<Map> getwarehousebyshopid(List<Long> list1) {
        return wmsWarehouseShopMapper.getwarehousebyshopid(list1);
    }

    @Override
    public int save(WmsWarehouseShop wmsWarehouseShop) {
        //wmsWarehouseShop.setWarehouseShopId(this.generateId());
        int num = wmsWarehouseShopMapper.insert(wmsWarehouseShop);

        List<Long> shopIds = new ArrayList<>();
        shopIds.add(wmsWarehouseShop.getShopId());
        List<ShopInfoDto> shopInfoDtos = smcFeignApi.getShopInfoByShopIds(shopIds);
        Long groupId = wmsWarehouseGroupService.findGroupId(wmsWarehouseShop.getShopId());

       if (shopInfoDtos != null && shopInfoDtos.size()>0 && groupId>0){
           System.out.println("保存仓库店铺绑定");
           uacUserFeignApi.updateUserGroup(shopInfoDtos.get(0).getUserId(),groupId);
       }

        return num;
    }
}
